//
//  BaseNetRequest.h
//  WeatherBar
//
//  Created by Bert on 2024/6/7.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "BaseNetRequestMacros.h"

NS_ASSUME_NONNULL_BEGIN
typedef void(^_Nullable BaseNetRequestSuccessBlock)(id responseObject);
typedef void(^_Nullable BaseNetRequestFailureBlock)(NSError *error);
typedef void (^_Nullable BaseNetRequestUploadProgressBlock)(NSProgress * _Nullable progress);

typedef NSURL * _Nullable (^_Nullable BaseNetRequestDestinationBlock)(NSURL *targetPath, NSURLResponse *response);
typedef void (^ _Nullable BaseNetRequestDownLoadSuccessBlock)(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath);

@interface BaseNetRequest : NSObject

/// 单例初始化
+ (instancetype)sharedInstance;

//网络访问前缀base URL，例如http://www.baidu.com/userlogin/username='aaa'，设定BaseUrl 为http://www.baidu.com/
@property (nonatomic ,copy) NSString *BaseUrl;

#pragma mark - 网络状态监控
+(void)startNetMonitoring;

+(void)stopNetMonitoring;

#pragma mark - 网络访问参数设定
//设置header中的数据
-(void)updateSessionManagerHeaderFields:(NSDictionary *)sessionManagerParameters timeoutInterval:(NSTimeInterval)timeoutInterval;

-(void)updateSessionManagerHeaderFields:(NSDictionary *)sessionManagerParameters;

#pragma mark - 网络数据访问方法

- (void)requestWithType:(RequestType)type
                    url:(NSString *)urlString
             parameters:(NSDictionary *)parameters
                success:(BaseNetRequestSuccessBlock)success
                failure:(BaseNetRequestFailureBlock)failure;
//真正请求：POST
- (void)postWithFullUrl:(NSString *)fullURLString parameters:(NSDictionary *)parameters success:(BaseNetRequestSuccessBlock )success failure:(BaseNetRequestFailureBlock )failure;
//真正请求：GET
- (void)getWithFullUrl:(NSString *)fullURLString parameters:(NSDictionary *)parameters success:(BaseNetRequestSuccessBlock )success failure:(BaseNetRequestFailureBlock )failure;
//真正请求：PUT
- (void)putWithFullUrl:(NSString *)fullURLString parameters:(NSDictionary *)parameters success:(BaseNetRequestSuccessBlock )success failure:(BaseNetRequestFailureBlock )failure;

-(void)cancelDataTask;

#pragma mark - 网络upload 访问方法,图片上传

-(void)upLoadWithPOST:(NSString *)urlString
           parameters:(NSDictionary *)parameters
                image:(NSData *)img
             progress:(BaseNetRequestUploadProgressBlock )progress
              success:(BaseNetRequestSuccessBlock)success
              failure:(BaseNetRequestFailureBlock)failure;

-(void)upLoadWithPOST:(NSString *)urlString
           parameters:(NSDictionary *)parameters
                image:(NSData *)img
            imageName:(NSString *)imageName
             fileName:(NSString *)fileName
             progress:(BaseNetRequestUploadProgressBlock )progress
              success:(BaseNetRequestSuccessBlock)success
              failure:(BaseNetRequestFailureBlock)failure;

-(void)upLoadWithPOST:(NSString *)urlString
           parameters:(NSDictionary *)parameters
           imageArray:(NSArray *)imageArray
             progress:(BaseNetRequestUploadProgressBlock )progress
              success:(BaseNetRequestSuccessBlock)success
              failure:(BaseNetRequestFailureBlock)failure;

-(void)cancelUploadTask;

#pragma mark - 网络download 访问方法

- (void)downLoadWithURL:(NSString *)fullURLString progress:(BaseNetRequestSuccessBlock)progress destination:(BaseNetRequestDestinationBlock )destination downLoadSuccess:(BaseNetRequestDownLoadSuccessBlock )downLoadSuccess failure:(BaseNetRequestFailureBlock)failure;

-(void)cancelDownloadTask;
@end

NS_ASSUME_NONNULL_END
